package com.lwp.lambda;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.util.Scanner;

/**
 * TestRobot
 *
 * @author lanwenping
 * @version 1.0
 * @date 2020/9/7 22:59
 */
public class TestRobot {

    private static Robot robot;

    static {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws AWTException {
        // TODO Auto-generated method stub
        try {
            // BFEBFBFF000906E9 BFEBFBFF000906E9
            long start = System.currentTimeMillis();
            Process process = Runtime.getRuntime().exec(
                    new String[] { "wmic", "cpu", "get", "ProcessorId" });
            System.out.println(process.toString());
            process.getOutputStream().close();
            Scanner sc = new Scanner(process.getInputStream());
            String property = sc.next();
            String serial = sc.next();
            System.out.println(property + ": " + serial);
            System.out.println("time:" + (System.currentTimeMillis() - start));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void test() throws AWTException {
        Robot r = new Robot();

        r.keyPress(65);
        r.keyPress(65);
        r.keyPress(65);
        r.keyRelease(65);
        r.keyRelease(65);
        r.keyRelease(65);

        // ctrol + shift + escape window下是任务管理器快捷键
        r.keyPress(KeyEvent.VK_CONTROL);//按下左Contrl  keycode为17
        r.keyPress(KeyEvent.VK_SHIFT);
        r.keyPress(KeyEvent.VK_ESCAPE);

        r.keyRelease(KeyEvent.VK_ESCAPE);

        r.keyRelease(KeyEvent.VK_SHIFT);

        r.keyRelease(KeyEvent.VK_CONTROL);//释放左Control键
    }

    // 键盘输入
    public static void input(String str){
        if(str!=null){
            for(char c : str.toCharArray()){
                pressKey(c);
            }
        }
    }
    private static void pressKey(int keyvalue) {
        robot.keyPress(keyvalue); // 按下按键
        robot.keyRelease(keyvalue); // 释放按键
    }
}
